/**
 * 匠言知识付费v2.0.0
 * Author: 山西匠言网络科技有限公司
 * 这不是一个免费软件，它受限于许可条款，你可以访问https://www.zsfzxkc.cn/获取更多详细信息。
 * This is not a free software, it under the license terms, you can visit https://www.zsffzxkc.cn/ get more details.
 */
<template>
	<view class="container">
		<form @submit="submit" :model="applyForm" v-if="base_set.smallapp.is_sh==0">
			<input v-model="applyForm.khh" class="name" type="text" placeholder="请输入bank" />
			<input v-model="applyForm.hzname" class="phone" type="text" placeholder="请输入name" />
			<input v-model="applyForm.cardnum" class="phone" type="text" placeholder="请输入card" />
			<input v-model="applyForm.txphone" class="phone" type="text" placeholder="请输入shouji" />
			<input v-model="applyForm.alipay" class="phone" type="text" placeholder="请输入alipay" />
			<input v-model="applyForm.wechat" class="phone" type="text" placeholder="请输入weixin" />
			<view class="submit">
				<button form-type="submit">保存</button>
			</view>
		</form>
		<view style="text-align: center;" v-else>
			<image src="../../../static/wudingdan.png" mode="aspectFit"></image>
		</view>
	</view>
</template>

<script>
	import { postSavedata } from '@/request/fenxiao'
	import {checkUserinfo} from '@/request/checkUserinfo'
	export default {
		data() {
			return {
				base_set:[],
				applyForm: {
					khh: '',
					hzname: '',
					cardnum: '',
					txphone: '',
					alipay: '',
					wechat:''
				}
			};
		},
		onShareAppMessage(res) {
			let path = getCurrentPages()
			let path_share = path[0].$page.fullPath
			let path_title = path[0].data.title
			let userinfo = uni.getStorageSync('userinfo')
			let base_set = uni.getStorageSync('base_set')
			if(userinfo.uid=='' || !userinfo.uid){
				uni.navigateTo({
					url:'../login/login'
				})
				return {
					title: '请先登录后再分享给好友',
					path: ''
				}
			}else{
				if (res.from === 'button') {
					
				}
				return {
					title: base_set.title,
					path: `${path_share}?pid=${userinfo.uid}`
				}
			}
		},
		onLoad() {
			checkUserinfo()
			var userinfo=uni.getStorageSync('userinfo')
			var userdata=userinfo.userdata
			
			let base_set = uni.getStorageSync('base_set')
			if (base_set) {
				this.base_set = base_set
			}
			
			this.applyForm.khh=userdata.khh
			this.applyForm.hzname=userdata.hzname
			this.applyForm.cardnum=userdata.cardnum
			this.applyForm.txphone=userdata.txphone
			this.applyForm.alipay=userdata.alipay
			this.applyForm.wechat=userdata.wechat
		},
		methods:{
			submit () {
				if(this.applyForm.khh == ( '' || null) || this.applyForm.hzname == ( '' || null) || this.applyForm.cardnum == ( '' || null) || this.applyForm.txphone == ( '' || null) || this.applyForm.alipay == ( '' || null) || this.applyForm.wechat == ( '' || null)) {
					uni.showToast({
						title: '资料不完整，请重试',
						duration: 2000,
						icon:'none'
					});
					return false;
				}
				if(!/^1[3-9]\d{9}$/.test(this.applyForm.txphone)) {
					uni.showToast({
						title: '手机号码格式不正确,请重试',
						duration: 2000,
						icon:'none'
					});
					return false;
				}
				let userinfo=uni.getStorageSync('userinfo')
				this.applyForm.uid = userinfo.uid
				
				postSavedata(this.applyForm).then(res => {
					console.log(res)
					if(res.data.code==0){
						uni.showToast({
							title: res.data.msg,
							duration: 2000
						});
						setTimeout(()=>{
							uni.navigateBack({
								
							})
						},1500)
					}else{
						uni.showToast({
							title: res.data.msg,
							icon:'none'
						});
					}
				})
			}
		}
	}
</script>

<style lang="less" scoped>

form {
	.name, .phone {
		width: 690upx;
		height: 80upx;
		border: 2upx solid #333;
		border-radius: 10upx;
		margin: 20upx 30upx 0;
		padding-left: 20upx;
		box-sizing: border-box;
		font-size: 30upx;
	}
	.submit {
		width: 100%;
		height: 120upx;
		background-color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
		position: fixed;
		left: 0;
		bottom: 0;
		button {
			width: 690upx;
			height: 80upx;
			background-color: blue;
			border-radius: 80upx;
			color: #fff;
			line-height: 80upx;
		}
	}
}

</style>
